package cn.outsourcing.supermarket.common.utils;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

/**
 * JSON 工具
 *
 * @author gzkemays
 * @since 2021/10/20 20:36
 */
public class JsonUtils {

  /**
   * 判断是否为 JSON
   *
   * @param txt 判断字符
   * @return 是否属于 JSON
   */
  public static boolean isJson(String txt) {
    boolean isJson = true;
    boolean isJsonArray = true;
    try {
      JSONObject.parseObject(txt);
    } catch (Exception e) {
      isJson = false;
    }
    try {
      JSONArray.parseArray(txt);
    } catch (Exception e) {
      isJsonArray = false;
    }
    return isJson || isJsonArray;
  }
}
